package com.arges.web.page;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 后台传递分页对象
 * 
 * @author arges
 */
public class PageInfo<T> implements Serializable
{
	private static final long serialVersionUID = 6467250963023046083L;

	private static final String ASC = "asc";

	private static final String DESC = "desc";

	private String orderByName = null;

	private String order = "desc";

	/**
	 * 当前页
	 */
	private int pageNo = 1;

	// 每页大小
	private int pageSize = 10;

	// 总的页数
	private long totalPage;

	// 是否含有上一页
	private boolean hasPre;

	// 是否含有下一页
	private boolean hasNext;

	private int first;

	/**
	 * 总记录数
	 */
	private long totalCount = -1;

	/**
	 * 当前页的结果集
	 */
	private List<T> result = new ArrayList<T>();

	public PageInfo()
	{
	}

	public PageInfo(int pageSize)
	{
		this.pageSize = pageSize;
	}

	public String getOrderByName()
	{
		return orderByName;
	}

	public void setOrderByName(String orderByName)
	{
		this.orderByName = orderByName;
	}

	public String getOrder()
	{
		return order;
	}

	public void setOrder(String order)
	{
		this.order = order;
	}

	public void setHasNext(boolean hasNext)
	{
		this.hasNext = hasNext;
	}

	public void setHasPre(boolean hasPre)
	{
		this.hasPre = hasPre;
	}

	/*
	 * 获取每次查询本页结果集时从第几条开始
	 */
	public int getFirst()
	{
		return ((pageNo - 1) * pageSize + 1);
	}

	public void setFirst(int first)
	{
		this.first = first;
	}

	/*
	 * 获取总页的页数
	 */
	public long getTotalPage()
	{
		long count = totalCount / pageSize;
		if (totalCount % pageSize > 0)
		{
			count++;
		}
		this.totalPage = count;
		return totalPage;
	}

	public void setTotalPage(long totalPage)
	{
		this.totalPage = totalPage;
	}

	/*
	 * 判断是否具有前一页
	 */
	public boolean isHasPre()
	{
		this.hasPre = (pageNo - 1 >= 1);
		return hasPre;
	}

	/*
	 * 判断是否具有下一页
	 */
	public boolean isHasNext()
	{
		this.hasNext = (pageNo + 1 <= getTotalPage());
		return hasNext;
	}

	public int getPageNo()
	{
		return pageNo;
	}

	public void setPageNo(int pageNo)
	{
		this.pageNo = pageNo;
		if (pageNo < 1)
		{
			this.pageNo = 1;
		}
	}

	public int getPageSize()
	{
		return pageSize;
	}

	public void setPageSize(int pageSize)
	{
		this.pageSize = pageSize;
		if (pageSize < 1)
		{
			this.pageSize = 1;
		}
	}

	public long getTotalCount()
	{
		return totalCount;
	}

	public void setTotalCount(long totalCount)
	{
		this.totalCount = totalCount;
	}

	public List<T> getResult()
	{
		return result;
	}

	public void setResult(List<T> result)
	{
		this.result = result;
	}

}
